#include <glib.h>

static void test_glib_spawning_proc_sync(void)
{
    GPtrArray *argv = NULL;
    gchar *stdout_str;
    gchar *stderr_str;
    gint estatus;
    GError *error = NULL;

    argv = g_ptr_array_new ();
    g_ptr_array_add (argv, (gpointer)"/bin/ls");
    g_ptr_array_add (argv, (gpointer)"-a");
    g_ptr_array_add (argv, (gpointer)"-l");
    g_ptr_array_add (argv, (gpointer)".");
    g_ptr_array_add (argv, (gpointer)"file_not_exist");
    g_ptr_array_add (argv, NULL);

    g_spawn_sync (NULL, (char**)argv->pdata, NULL, G_SPAWN_DEFAULT, NULL, NULL, &stdout_str, &stderr_str, &estatus, &error);
    g_assert_no_error (error);

    g_print("%s \n", stdout_str);
    g_print("%s \n", stderr_str);

    g_free(stdout_str);
    g_free(stderr_str);
    g_ptr_array_free (argv, TRUE);

    return;
}

gint main(gint argc, gchar **argv) 
{
    test_glib_spawning_proc_sync();

    return 0;
}
